package com.leyou.item.web;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 根据分类id查询规格组参数
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupByCid(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.querySpecGroupByCid(id));
    }

    /**
     * 查询规格参数
     * @param gid           规格组id
     * @param cid           分类id
     * @param searching     是否查询
     * @return              规格参数的DTO集合
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> querSpecParam(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching
    ){
        return ResponseEntity.ok(specService.querSpecParam(gid,cid,searching));
    }

    /**
     * 根据分类id查询规格组和组内的参数
     * @param id    分类id
     * @return
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecByCategoryId(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.querySpecByCategoryId(id));
    }





}
